import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.Objects;

class Money implements Cloneable {
    public double m = 12.5;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}


class Person implements Cloneable {
    public String name;
    public int age;
    public Money money = new Money();
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();
        tmp.money = (Money) this.money.clone();
        return tmp;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    /*@Override
    public boolean equals(Object obj) {
        Person tmp = (Person) obj;
        return this.name.equals(tmp.name)
                && this.age == tmp.age;
    }*/
}



public class Test {
    public static void main(String[] args) {
        Person person = new Person("张三",18);
        Person person2 = new Person("张三",18);
        int a = 10;
        int b = 10;
        System.out.println(a == b);
        System.out.println(person == person2);//比较的是引用的地址
        System.out.println(person.equals(person2));
    }









    public static void main1(String[] args) throws CloneNotSupportedException {
        Person person = new Person("张三",18);
        Person person2 = (Person) person.clone();//调用克隆方法生成副本
        System.out.println("person " + person.money.m);
        System.out.println("person2 " + person2.money.m);
        System.out.println("========================");
        person.money.m = 99.99;
        System.out.println("person " + person.money.m);
        System.out.println("person2 " + person2.money.m);
    }
}
